export

abstract suspend fun export(block: DesignBlock, mimeType: MimeType, options: ExportOptions? = null, progressCallback: (ExportPdfProgress) -> Unit? = null, onPreExport: suspend Engine.() -> Unit = {}, uriResolver: suspend (Uri) -> Uri? = null): ByteBuffer

Exports a design block element as a file of the given mime type. Performs an internal update to resolve the final layout for the blocks. Note: The export happens in a background thread and the Engine instance in the onPreExport lambda is a separate instance and is alive until the suspending function resumes. Use this lambda to configure the background engine for export. If uriResolver is provided it will be set on the background engine before the exported scene is loaded and once more after onPreExport is invoked (so it takes precedence if onPreExport also sets a resolver).

Return

the exported data. From Android 9 a buffer of 1 MiB or more is a direct buffer over the bytes of the engine, without a copy and without a backing array: read it with get, not array. A PDF stays in a temp file, which goes once the buffer and every view of it are collected.

Parameters

block

the design block element to export.

mimeType

the mime type of the output file.

options

the options for exporting the block type

progressCallback

optional callback reporting the number of pages exported so far and the total number of pages. Invoked after each page has been serialized into the document. Only called for PDF exports; for any other mime type it is never invoked.

onPreExport

the lambda to configure the engine before export. This lambda is called on a background thread, and the Engine parameter of this lambda is a separate engine instance running in that background thread.

uriResolver

optional async resolution function that accepts both relative and absolute uri and returns an absolute uri.


abstract suspend fun export(block: DesignBlock, output: OutputStream, mimeType: MimeType = MimeType.PDF, options: ExportOptions? = null, progressCallback: (ExportPdfProgress) -> Unit? = null, onPreExport: suspend Engine.() -> Unit = {}, uriResolver: suspend (Uri) -> Uri? = null)

Exports a design block element as a PDF and writes the bytes into output while they are produced, so the document is never held in memory as a whole. Prefer this over the export that returns a ByteBuffer for large multi-page documents such as photo books and magazines: the peak memory is the working set of one page, whatever the number of pages. Performs an internal update to resolve the final layout for the blocks. Note: The export happens in a background thread and the Engine instance in the onPreExport lambda is a separate instance and is alive until the suspending function resumes. Use this lambda to configure the background engine for export. If uriResolver is provided it will be set on the background engine before the exported scene is loaded and once more after onPreExport is invoked (so it takes precedence if onPreExport also sets a resolver). Note: output is written from that background thread with one write for each chunk, so a slow destination slows the encoder down and the chunks do not queue up in memory. ExportOptions.pdfChunkSize bounds the size of a chunk. The caller keeps the ownership of output and closes it, for example with use. Note: When the export fails or the calling coroutine is cancelled, the export stops and output holds an incomplete document. A write that blocks delays the cancellation until it returns.

Parameters

block

the design block element to export.

output

the destination the exported bytes are written to.

mimeType

the mime type of the output file. A streamed export supports MimeType.PDF only; any other mime type throws an EngineException.

options

the options for exporting the block type

progressCallback

optional callback reporting the number of pages exported so far and the total number of pages. Invoked after each page has been serialized into the document.

onPreExport

the lambda to configure the engine before export. This lambda is called on a background thread, and the Engine parameter of this lambda is a separate engine instance running in that background thread.

uriResolver

optional async resolution function that accepts both relative and absolute uri and returns an absolute uri.

Throws

when a write to output fails. The export stops at that chunk, and any other exception that a write throws reaches the caller the same way.


abstract fun export(block: DesignBlock, options: ExportOptions? = null, progressCallback: (ExportPdfProgress) -> Unit? = null, onPreExport: suspend Engine.() -> Unit = {}, uriResolver: suspend (Uri) -> Uri? = null): Flow<ByteBuffer>

Exports a design block element as a PDF and emits the bytes as chunks while they are produced, so the document is never held in memory as a whole. This is the same export as the export overload that takes an OutputStream. Prefer that overload when the destination is a file, a content:// target or an upload stream, and this one when the chunks feed a coroutine pipeline. Performs an internal update to resolve the final layout for the blocks. Note: The returned flow is cold. Each collection runs one export, which starts when the collection starts, and the flow completes after the last chunk. Collect it on the engine thread, like every other engine call. Note: The flow has no buffer. The encoder waits until the collector has taken a chunk, so a slow collector slows the encoder down and the chunks do not queue up in memory. A collector that keeps the chunks, for example with toList(), holds the whole document in memory again. Note: When the collector leaves or its coroutine is cancelled, the export stops. Note: This overload has no mimeType parameter, because a streamed export supports MimeType.PDF only. Note: The export happens in a background thread and the Engine instance in the onPreExport lambda is a separate instance and is alive until the collection ends. Use this lambda to configure the background engine for export. If uriResolver is provided it will be set on the background engine before the exported scene is loaded and once more after onPreExport is invoked (so it takes precedence if onPreExport also sets a resolver).

Return

a cold flow of the chunks of the document, in order. Each chunk is a new buffer, so the collector may keep it. ExportOptions.pdfChunkSize bounds the size of a chunk.

Parameters

block

the design block element to export.

options

the options for exporting the block type

progressCallback

optional callback reporting the number of pages exported so far and the total number of pages. Invoked after each page has been serialized into the document.

onPreExport

the lambda to configure the engine before export. This lambda is called on a background thread, and the Engine parameter of this lambda is a separate engine instance running in that background thread.

uriResolver

optional async resolution function that accepts both relative and absolute uri and returns an absolute uri.


abstract suspend fun export(blocks: List<DesignBlock>, mimeType: MimeType, options: ExportOptions? = null, progressCallback: (ExportPdfProgress) -> Unit? = null, onPreExport: suspend Engine.() -> Unit = {}, uriResolver: suspend (Uri) -> Uri? = null): List<ByteBuffer>

Exports multiple design block elements as files of the given mime type. Performs an internal update to resolve the final layout for the blocks. This method is more memory efficient than calling export repeatedly for multiple blocks as it reuses a single worker engine for all exports. Note: The export happens in a background thread and the Engine instance in the onPreExport lambda is a separate instance and is alive until the suspending function resumes. Use this lambda to configure the background engine for export. If uriResolver is provided it will be set on the background engine before the exported scene is loaded and once more after onPreExport is invoked (so it takes precedence if onPreExport also sets a resolver).

Return

the exported data for each block, in the same order as the input blocks. From Android 9 a buffer of 1 MiB or more is a direct buffer over the bytes of the engine, without a copy and without a backing array: read it with get, not array. A PDF stays in a temp file, which goes once the buffer and every view of it are collected.

Parameters

blocks

the design block elements to export.

mimeType

the mime type of the output files.

options

the options for exporting the block type

progressCallback

optional callback reporting the number of pages exported so far and the total number of pages. Invoked after each page has been serialized into the document. Only called for PDF exports; for any other mime type it is never invoked. Progress restarts at the first page for every block.

onPreExport

the lambda to configure the engine before export. This lambda is called on a background thread, and the Engine parameter of this lambda is a separate engine instance running in that background thread.

uriResolver

optional async resolution function that accepts both relative and absolute uri and returns an absolute uri.